<?php
// +----------------------------------------------------------------------
// | quanli team
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2020 http://www.fistforward.com/ All rights reserved.
// +----------------------------------------------------------------------
// | create by allen.qiang
// +----------------------------------------------------------------------


/**
 * 积分商城
 * @package  htdocs
 * @subpackage  quanliadmin
 * @author   create by allen.qiang
 */
require('module/base/promotionHandler.class.php');

class pa_pointsMall {

	public function execute() {
		global $G_PGLOB ;
		if (isset($_REQUEST['operFlg'])) {
		
			switch($_REQUEST['operFlg']) {
			
				case 1: //积分商城初始化
					$this->init();
					break;
					
				case 2: //添加积分商城促销
					$this->addPointsMall();
					break;
					
				case 3: //编辑积分商城促销
					$this->editPointsMall();
					break;
				
				default:
					$G_PGLOB->smarty->assign('msg', '参数错误，请审核后再操作');
					$G_PGLOB->smarty->display('comm/error.tpl');
			}
		}
	}
    
	/**
	 * 积分商城初始化
	 *
	 */
	private function init(){
		global $G_PGLOB;
		
		$G_PGLOB->smarty->display('promotion/pointsMall.tpl');
	}
	
	/**
	 * 添加积分商城促销
	 *
	 */
	private function addPointsMall(){
		global $G_PGLOB;
		
		//帐户礼品券
        $accountCoupon = $G_PGLOB->DBCA->stmt_query('SELECT couponID,couponName FROM promotion_coupon WHERE couponType=2 AND startDate<=? AND endDate>=?' ,'ss' , $G_PGLOB->sys_datetime,$G_PGLOB->sys_datetime);

        $G_PGLOB->smarty->assign('accountCoupon' , $accountCoupon);
		
		$G_PGLOB->smarty->assign('operFlg', 2);
		$G_PGLOB->smarty->display('promotion/pointsMallAdd.tpl');
	}
	
	/**
	 * 编辑积分商城促销
	 *
	 */
	private function editPointsMall() {
		global $G_PGLOB;

        if (!isset($_REQUEST['id']) || !is_numeric($_REQUEST['id'])) {
            $G_PGLOB->smarty->assign('msg', '参数错误');
            $G_PGLOB->smarty->display('comm/error.tpl');
            die() ;
        }

        $promotionHandler = new promotionHandler( $G_PGLOB->DBCA );
        
        $arg_mall_array = array(
        	'promotionID' => $_REQUEST['id']
        );
        $pointsMall_result = $promotionHandler->searchPointsMall( $arg_mall_array );
    	if ( !$pointsMall_result ) {
        	$G_PGLOB->smarty->assign('msg', '没有找到促销信息');
            $G_PGLOB->smarty->display('comm/error.tpl');
            die() ;
        }
        
        $pointsMall_detail_result = $promotionHandler->searchPointsMallDetail( $arg_mall_array );
        if ( !$pointsMall_detail_result ) {
        	$G_PGLOB->smarty->assign('msg', '没有找到促销详情信息');
            $G_PGLOB->smarty->display('comm/error.tpl');
            die() ;
        }
        
        if ($pointsMall_result[0]['type'] == 1) { //积分兑换优惠券
        	//帐户礼品券
	        $accountCoupon = $G_PGLOB->DBCA->stmt_query('SELECT couponID,couponName FROM promotion_coupon WHERE couponType=2 AND startDate<=? AND endDate>=?' ,'ss' , $G_PGLOB->sys_datetime,$G_PGLOB->sys_datetime);
	        $G_PGLOB->smarty->assign('accountCoupon' , $accountCoupon);
        }
		
        $G_PGLOB->smarty->assign('operFlg', 3);
        $G_PGLOB->smarty->assign('pointsMall', $pointsMall_result[0]);
        $G_PGLOB->smarty->assign('pointsMallDetail', $pointsMall_detail_result);
        $G_PGLOB->smarty->display('promotion/pointsMallAdd.tpl');
	}
	
    
}